<script type="text/javascript">
$(function(){
	var pg = App.base.fileIndex.ui, pp = pg.params
		, hd = pg.children('.head'), bd = pg.children('.body')
		, gd = pg.seek('grid');

	//配置文件
	gd.mac('grid', {
		cols : [{
			field: 'code', title : '英文编号', width: 180,
			render: function(r, tr){
				r.proj = pp;
				return $('<span class="a"></span>').click(function(){
					App.open({
						title: '文件列表',
						ctx: 'base',
						action:'fileEdit',
						model: true,
						params: r
					}, function(){
						gd.load();
					});
				}).append(r.code);
			}
		},{
			field: 'name', title : '文件名称', width: 180
		},{
			field: 'type', title : '类型', width: 80,
			render: function(r) {
				return Cache.base.file.type[r.type];
			}
		},{
			field: 'version', title : '版本号', width: 160,
			render: function(r){
				r.proj = pp;
				return $('<span class="a"></span>').click(function(){
					App.show({
						ctx: 'base',
						action: 'fileVersionIndex',
						params: r
					}, $.noop, function(){
						App.show({
							ctx: 'base',
							action: 'fileIndex',
							params: pp
						}, pg.parent());
					});
				}).append(r.version).append('&nbsp;&nbsp;更多版本');
			}
		},{
			field: 'sourcePath', title : '源码路径', width: 180
		},{
			field: 'deployPath', title : '部署路径', width: 180
		},{
			field: 'id', title : '操作', width: 80,
			render: function(r){
				return $('<span class="a center"></span>').click(function(){
					mac.confirm('确定要' + $(this).text() + '此实例吗？', function(){
						$.post(App.ctx + '/file/delete.do', {
							id: r.id
						},function(){
							gd.load();	
						});
					}).append('删除');
				});
			}
		}],
		loader: {
			url: App.ctx + '/file/list.do',
			params: {
				projId: pp.id,
				pageNo: 1, pageSize: 50
			},
			autoLoad: true
		},
		pagerLength: 10
	});
	hd.seek('add').click(function(){
		App.open({
			title: '添加文件',
			ctx: 'base',
			action: 'fileEdit',
			model: true,
			params: { proj: pp.proj.id }
		}, function(){
			gd.load()
		});
	});
	hd.seek('key').keydown(function(e) {
		if (e.keyCode == 13)
			gd.load({ key : $(this).val() });
	});
	hd.seek('find').click(function(e){
		gd.load({ key : $(hd.seek('key')).val() });
	});
	
	function adjust(){
		var h = pg.parent().height();
		bd.height(h - hd.height() - 32);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
});
</script>
<div class="head">
	<div class="fl">
		<button name="add">添加文件</button>
		&nbsp;&nbsp;
	</div>
	<div class="fl">
		&nbsp;&nbsp;&nbsp;&nbsp;关键字：
		<input type="text" name="key" placeholder="查找" />
		<button name="find">查找</button>
		&nbsp;&nbsp;&nbsp;&nbsp;
	</div>
	<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="body">
	<div class="grid" name="grid"></div>
</div>